package com.l.Thread.exer;

/**
 * 例子：创建三个窗口买票，总票数为100张，使用实现Runnable接口的方式
 *
 *
 * @author Mc.Chai
 * @program: Java基础
 * @create 2021-11-10-20:26 20:26
 */
public class TestWindow {
    public static void main(String[] args) {
        Window window=new Window();
        Thread thread=new Thread(window);
        Thread thread2=new Thread(window);
        Thread thread3=new Thread(window);
        thread.setName("窗口一");
        thread2.setName("窗口二");
        thread3.setName("窗口三");
        thread.start();
        thread2.start();
        thread3.start();

    }
}
class Window implements Runnable{
    private int ticket=100;
    @Override
    public void run() {
        synchronized (this){
            while (true){
                if (ticket>0){
                    System.out.println(Thread.currentThread().getName()+":"+ticket);
                    ticket--;
                }else{
                    break;
                }
            }
        }
    }
}
